#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/input.h> // 系统定义输入设备操作的API

int main(int argc, char const *argv[])
{
    //打开触摸屏设备
    int tp = open("/dev/input/event0", O_RDONLY);

    //循环读取 /dev/input/event0
    struct input_event buf;
    bool flag = false;
    bool button = false;
    while(1){
        bzero(&buf, sizeof(buf));
        read(tp, &buf, sizeof(buf));
        if(buf.type == EV_KEY && buf.code == BTN_TOUCH){
            if(buf.value == 0){
                printf("松开\n");
                break;
            }
            if(buf.value > 0 && !button){
                printf("按下\n");
                button = true;
            }
        }
        if(button && buf.type == EV_ABS && buf.code == ABS_X && !flag){
            flag = true;
            fprintf(stderr, "(%d, ", buf.value);
        }
        if(button && buf.type == EV_ABS && buf.code == ABS_Y && flag){
            flag = false;
            fprintf(stderr, "%d)\n", buf.value);
        }
    }
    return 0;
}
